import { Http } from "@/utils/http";
import {
  TeamMemberInventoryParams,
  EvaluationRankingParams,
  UserCompareParams,
  UserAssessmentParams, ReportDataType
} from "./teamSalesPerformance.d";

export * from "./teamSalesPerformance.d";

const configDefault = {
    headers: {
      "Content-Type": "application/json"
    },
    timeout: 60000,
    baseURL: import.meta.env.VITE_XMATE_BASE_API,
    data: {}
  };
// 这里域名变了使用新的
const xmateHttp = new Http(configDefault);

export const getTeamMemberInventoryAPI = (params: TeamMemberInventoryParams) => {
    const { params : data } = params;
    return xmateHttp.request({
      url: `/rest/api/org/${params.orgId}/dept/${params.deptId}/users/inventory/capability`,
      method: "POST",
      data
    });
};

export const getAssessmentSettingsAPI = () => {
  return xmateHttp.request({
    url: "/rest/api/xmate/configs/topic/dimension/sales_tasks/assessment/settings",
    method: "GET"
  });
};

export const getRankScoresAPI = (v: EvaluationRankingParams) => {
  const { orgId, deptId, userOrDeparment, dimensionId, dataType, params : data  } = v;
  return xmateHttp.request({
    url: `/rest/api/org/${orgId}/dept/${deptId}/${userOrDeparment}/${dataType}/dimension/${dimensionId}/scores`,
    method: "POST",
    data
  });
};
//取得销售表现均值
export function getDeptSalesDimensionsScoreAPI(params: any) {
  const { params : data } = params;
  return xmateHttp.request({
    url: `/rest/api/org/${params.orgId}/dept/${params.deptId}/depts/${params.dataType}/dimension/score`,
    method: "POST",
    data
  });
}

// 个人表现趋势数据
export const getUserTrendsAPI = (params: any) => {
  const { params : data } = params;
  return xmateHttp.request({
    url: `/rest/api/org/${params.orgId}/dept/${params.deptId}/users/${params.userId}/${params.dataType}/trends`,
    method: "POST",
    data
  });
};

// 获取能力趋势 ai分析
export const getUserPerformanceTrendAnalysisAPI = (data: any) => {
  console.log("个人趋势 aiParam api", data);
  return xmateHttp.request({
    url: "/rest/api/customer/user/performance/trend/analysis",
    method: "POST",
    data
  });
};

// 获取销售表现对比
export const getUserCompare = (params: UserCompareParams) => {
  const { params : data } = params;
  return xmateHttp.request({
    url: `/rest/api/org/${params.orgId}/dept/${params.deptId}/users/${params.dataType}/compare`,
    method: "POST",
    data
  });
};

// 获取个人能力图
export const getUserAssessment = (params: UserAssessmentParams) => {
  const { orgId, userId, dataType, reportType } = params;
  return xmateHttp.request({
    url: `/rest/api/org/${orgId}/user/${userId}/assessment/${dataType}/${reportType}`,
    method: "POST"
  });
};

// 获取用户个人指标数据
export const getUserReport = (deptId: string, dataType: ReportDataType) => {
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${deptId}/report/${dataType}/users`,
    method: "GET"
  });
};


// 获取达标分数
export const getPassScore = (orgId: string) => {
  return xmateHttp.request({
    url: `rest/api/org/${orgId}/standard/setting`,
    method: "GET"
  });
};


